package com.wanshu.sys.controller;

import com.wanshu.common.util.PageUtils;
import com.wanshu.sys.entity.SysRole;
import com.wanshu.sys.model.SysRoleQueryDTO;
import com.wanshu.sys.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author 波哥
 * @since 2024-05-28
 */
//@CrossOrigin    //放开跨域限制 springSecurity拦截器加入后失效
@Api(tags = "系统角色", value = "SysRole")
@RestController
@RequestMapping("/sys/sysRole")
public class SysRoleController {

    @Autowired
    private ISysRoleService sysRoleService;

    @ApiOperation(notes = "分页角色信息", value = "查询分页角色")
    @GetMapping("/list")
    public PageUtils list(SysRoleQueryDTO queryDTO){
        return sysRoleService.queryPage(queryDTO);
    }

    @ApiOperation(notes = "添加角色", value = "添加角色")
    @PostMapping("/save")
    public String saveRole(@RequestBody SysRole sysRole){
        sysRoleService.saveOrUpdateRole(sysRole);
        return "success";
    }

    @GetMapping("/checkRoleName")
    public String checkRoleName(@RequestParam String roleName){
        boolean checkRoleName = sysRoleService.checkRoleName(roleName);
        if(checkRoleName){
            return "success";
        }
        return "fail";
    }

    @GetMapping("/delete")
    public String deleteRole(@RequestParam Long roleId){
        boolean result = sysRoleService.deleteRole(roleId);
        if(result){
            return "1";
        }
        return "0";
    }

}
